<?php
class goodsSupplier extends supplier {

    private $supplierType = array( '厂家', '批发商', '阿里批发商' );
    private $supplieGrand = array( 1, 2, 3 );
    private $supplieDiscount = array( '25折', '26折', '27折', '28折', '29折', '30折', '31折', '32折', '33折', '34折', '35折', );
    private $name = "供应商";

    public function __construct() {
        parent::__construct();
        $this->type = G( 'a' ) == 'index' ? '' : G( 'a' );
    }

    public function index( $c, $a ) {
        $this->table = 'supplier';

       $result = $this->find(array('supplierNo'=>$this->admin['myId']));

        include $this->display( $c );
    }

    public function edit( $c, $a ) {
        if ( !$id = intval( G( 'id' ) ) ) {
            $this->error();
            exit;
        }
        $this->table = 'supplier';
       // 数据库表名
        $result = $this->find( array( 'id' => $id ) ); // 查找数据
        include $this->display( $c ); // 加载模板
    }

    # 删除商品
    public function del( $c ) {
        if ( !$id = intval( G( "id" ) ) ) {
            exit( '非法删除商品' );
        }

        #删除商品
        $this->table = 'supplier';
        $msg = $this->delete( array( "id" => $id ) ) ? 'success' : 'failed';


        exit( $msg );
    }

    public function add( $c, $a ) {
        include $this->display( $c );
    }

    public function save( $c ) {
        # 获取表单数据
        foreach ( $_POST as $key => $val ) {
            if ( $key == 'businessType' ) {
                $string = implode( glue, $val );
                $rows[ $key ] = htmlspecialchars( trim( $string ) );
                continue;
            }
            $rows[ $key ] = htmlspecialchars( trim( $val ) );
        }

        # 注意 表单字段必须跟数据库表字段名一样
        //$this->table = ''; // 数据库表名
        $this->table = 'supplier'; // 数据库表名
        if ( $id = intval( G( "id" ) ) ) {
            $msg = $this->update( array( 'id' => $id ), $rows ) ? 'success' : 'failed'; //更新供货商
        } else {
            $msg = $this->create( $rows ) ? 'success' : 'failed'; // 添加供货商
        }
        exit( $msg );
    }

    public function get_date() {
        echo date( G( 'format', $this->setting[ 'timeformat' ] ) );
    }

}